package org.railage.server.entities;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.NamedNativeQuery;
import org.railage.common.dto.StationOfRouteDTO;

/**
 * StationOfRoute entity
 * 
 * @author Cyril Fertikov
 * 
 */
@NamedNativeQuery(
		name = "getOrderedStationsOfRoute", 
		query = "call proc_get_ordered_stations_of_route(:routeName)", 
		resultClass = StationOfRoute.class
)
@Entity
@Table(name = "station_of_route")
public class StationOfRoute implements Serializable {
	private static final long serialVersionUID = -1892433528405141862L;

	@Id
	@Column(name = "id")
	private int id;

	@ManyToOne
	@JoinColumn(name = "route_id")
	private Route route;

	@ManyToOne
	@JoinColumn(name = "station_id")
	private Station station;

	@Column(name = "station_order")
	private int stationOrder;

	@Column(name = "time_after_start")
	private String timeAfterStart;

	@Column(name = "time_on_station")
	private String timeOnStation;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Route getRoute() {
		return route;
	}

	public void setRoute(Route route) {
		this.route = route;
	}

	public Station getStation() {
		return station;
	}

	public void setStation(Station station) {
		this.station = station;
	}

	public int getStationOrder() {
		return stationOrder;
	}

	public void setStationOrder(int stationOrder) {
		this.stationOrder = stationOrder;
	}

	public String getTimeAfterStart() {
		return timeAfterStart;
	}

	public void setTimeAfterStart(String timeAfterStart) {
		this.timeAfterStart = timeAfterStart;
	}

	public String getTimeOnStation() {
		return timeOnStation;
	}

	public void setTimeOnStation(String timeOnStation) {
		this.timeOnStation = timeOnStation;
	}

	public StationOfRouteDTO toDTO() {
		StationOfRouteDTO dto = new StationOfRouteDTO();
		dto.setId(id);
		dto.setRouteName(route.getName());
		dto.setStationName(station.getName());
		dto.setStationOrder(stationOrder);
		dto.setTimeAfterStart(timeAfterStart);
		dto.setTimeOnStation(timeOnStation);
		return dto;
	}

}
